package com.veer.shop.controller.admin;

import com.veer.shop.annotation.ApiControllerLog;
import com.veer.shop.annotation.ApiSecured;
import com.veer.shop.config.ApiUrlConfig;
import com.veer.shop.param.AdminRoleParam;
import com.veer.shop.pojo.AdminRole;
import com.veer.shop.pojo.ResponseData;
import com.veer.shop.service.impl.admin.AdminRoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户角色控制器
 *
 * @author WangBin
 * @date 2020-12-04 20:14
 */
@RestController
public class RoleController {
    @Autowired
    private AdminRoleServiceImpl adminRoleServiceImpl;

    /**
     * 新增/更新角色
     */
    @ApiSecured
    @ApiControllerLog(description = "新增/更新角色")
    @RequestMapping( path = ApiUrlConfig.API_ADMIN_ROLE_UPDATE_URL, method = RequestMethod.POST)
    public ResponseData<?> update(@RequestBody AdminRole adminRole)
    {
        return adminRoleServiceImpl.update(adminRole);
    }

    /**
     * 查询角色列表
     *
     * @param adminRoleParam
     * @return
     */
    @ApiSecured
    @ApiControllerLog(description = "查询角色列表")
    @RequestMapping( path = ApiUrlConfig.API_ADMIN_ROLES_URL, method = RequestMethod.POST)
    public ResponseData<?> getList(@RequestBody(required=false) AdminRoleParam adminRoleParam)
    {
        return adminRoleServiceImpl.getList(adminRoleParam);
    }

    /**
     * 获取角色详情
     */
    @ApiControllerLog(description = "获取管理员Token")
    @RequestMapping(path = ApiUrlConfig.API_ADMIN_ROLE_GET_URL, method = RequestMethod.GET)
    public ResponseData<?> get(@RequestParam(name = "role_id")Integer role_id)
    {
        return adminRoleServiceImpl.get(role_id);
    }

    /**
     * 删除角色详情
     */
    @ApiControllerLog(description = "删除角色详情")
    @RequestMapping(path = ApiUrlConfig.API_ADMIN_ROLE_DELETE_URL, method = RequestMethod.POST)
    public ResponseData<?> delete(@RequestParam(name = "role_id")String role_id)
    {
        return adminRoleServiceImpl.delete(role_id);
    }
}
